export default {
  data(){
    return {
      urlEnum: '',
      page: {
        current: 1, // 当前在第几页
        sizes: [10, 20, 50, 100], // 每页显示多少条数据
        size: 10, // 每页显示多少条
        total: 0 // 共多少条数据
      }
    }
  },
  created(){
    this.getList()
  },
  methods: {
    // 获取列表
    getList(isSearch = false){
      if(this.urlEnum == '') return
      this.axios.post(this.urlEnum,{
        ...this.searchForm,
        current: isSearch ? 1 : this.page.current,
        size: this.page.size
      }).then(result => {
        // 赋值给列表
        this.tableData = result.data.list
        // 共几条
        this.page.total = result.data.totalCount
      })
    },
    // 切换每页多少条
    handleSizeChange(val){
      this.page.size = val
      this.getList()
    },
    // 切换到第几页
    handleCurrentChange(val){
      this.page.current = val
      this.getList()
    },
    // 关闭当前页签
    closeMe(){
      let visitedViews = this.$store.state.tagsView.visitedViews
      let view = visitedViews.filter(v => v.name == this.$route.name)
      this.$store.dispatch('tagsView/delView', view[0]).then(() => {
        const latestView = visitedViews.slice(-1)[0]
        if (latestView) {
          // 只剩一个就选中这个
          this.$router.push(latestView.fullPath)
        } else {
          // 如果全部关闭了，就跳转到首页
          if (view.name === 'home') {
            this.$router.replace({ path: '/home' + view.fullPath })
          } else {
            this.$router.push('/')
          }
        }
      })
    },
  }
}